package com.gem.day13;

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * 本类用来演示Java IO流之字符输入流
 * 
 * @author easonsy
 * 2020年8月6日 上午9:02:55
 */
public class ReaderDemo {
	public static void main(String[] args) {
		//根据源头和目选择合适的流
		/*try (Reader r = new FileReader("D:\\day12笔记.txt")) {
			//定义变量保存读取到的值
			int len = -1;
			//循环读取
			while ((len = r.read()) != -1) {
				System.out.print((char) len);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}*/

		//使用缓冲流提升读取性能
		try (BufferedReader r = new BufferedReader(new FileReader("D:\\day12笔记.txt"))) {
			//定义变量保存读取到的值
			String line = null;
			//循环读取每一行
			while ((line = r.readLine()) != null) {
				//实现业务逻辑
				//例如: 模拟代码混淆
				/*if (line.length() == 0 || line.trim().length() == 0) {
					continue;
				}
				System.out.println(line.trim());*/

				System.out.print(line);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
